package com.gitee.melin.bee.core.enums.mvc;

import org.springframework.core.convert.converter.Converter;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * Created by libinsong on 2020/9/9 9:41 下午
 */
public class StringToInstantConverter implements Converter<String, Instant> {

    private final static DateTimeFormatter fmt =
            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneOffset.systemDefault());

    @Override
    public Instant convert(String source) {
        return Instant.from(fmt.parse(source));
    }

    public static void main(String[] args) {
        Instant instant = Instant.from(fmt.parse("2022-12-31 16:38:35"));
        System.out.println(instant);
    }
}
